//
//  UserAccount.swift
//  JIMWeiBo
//
//  Created by 陈恒均 on 2018/2/10.
//  Copyright © 2018年 陈恒均. All rights reserved.
//

import UIKit

class UserAccount: NSObject,NSCoding {
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(avatar_large, forKey: "avatar_large")
        aCoder.encode(screen_name, forKey: "screen_name")
    }
    
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as? NSDate
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String
        screen_name = aDecoder.decodeObject(forKey: "screen_name") as? String
        
    }
    
    
    var access_token : String?
    /// 过期时间-->秒
    var expires_in : TimeInterval = 0.0

    /// 用户ID
    var uid : String?
    
    var expires_date : NSDate?

    var screen_name : String?


    var avatar_large : String?
    
    
    init(dict:[String : Any]) {
        super.init()
//        setValuesForKeys(dict)
        access_token = dict["access_token"] as? String
        expires_in = dict["expires_in"] as! TimeInterval
        uid = dict["uid"] as? String
        expires_date = NSDate(timeIntervalSinceNow: expires_in)
     
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    
//    override var description: String{
//        return dictionaryWithValues(forKeys: ["access_token", "expires_in", "uid"]).description
//    }
}
